home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / os2 / adaptor.zip / ADAPT.ZIP / adaptor / src / dataflow.c < prev    next >
Text File  |  1994-01-03  |  24KB  |  1,018 lines

  1. # include "DataFlow.h"
  2. # include "yyDFlow.w"
  3. # include <stdio.h>
  4. # if defined __STDC__ | defined __cplusplus
  5. #  include <stdlib.h>
  6. # else
  7.    extern void exit ();
  8. # endif
  9. # include "Tree.h"
  10. # include "DepGraph.h"
  11.  
  12. # ifndef NULL
  13. # define NULL 0L
  14. # endif
  15. # ifndef false
  16. # define false 0
  17. # endif
  18. # ifndef true
  19. # define true 1
  20. # endif
  21.  
  22. # ifdef yyInline
  23. # define yyALLOC(tree, free, max, alloc, nodesize, make, ptr, kind) \
  24.   if ((ptr = (tree) free) >= (tree) max) ptr = alloc (); \
  25.   free += nodesize [kind]; \
  26.   ptr->yyHead.yyMark = 0; \
  27.   ptr->Kind = kind;
  28. # else
  29. # define yyALLOC(tree, free, max, alloc, nodesize, make, ptr, kind) ptr = make (kind);
  30. # endif
  31.  
  32. # define yyWrite(s) (void) fputs (s, yyf)
  33. # define yyWriteNl (void) fputc ('\n', yyf)
  34.  
  35. # line 10 "DataFlow.puma"
  36.  
  37. # include "Tree.h"
  38. # include "DepGraph.h"
  39. # include "Unparse.h"    /* for printing node information */
  40.  
  41. # define tExits int
  42. typedef DepNodeSet* pDepNodeSet;
  43.  
  44. tTree LoopList;
  45. tTree Stat;     /* global for the last statement */
  46. tDepNode DN;
  47.  
  48. int DepErrorCount;    /* Counter for Errors */
  49.  
  50. FILE *DepFile;        /* will be exported */
  51.  
  52. short IsLoopVar (name)
  53. tIdent name;
  54. {  short found;
  55.    tTree HL, HE, Id;
  56.    HL = LoopList;
  57.    found = 0;
  58.    while ((HL->Kind != kACF_EMPTY) && (!found))
  59.      {  HE = HL->ACF_LIST.Elem;
  60.         if (HE->Kind == kACF_DO)
  61.            {  Id = HE->ACF_DO.DO_ID;
  62.               if (Id->Kind == kLOOP_VAR)
  63.                 found = (Id->LOOP_VAR.LOOP_VARNAME->VAR_OBJ.Ident == name);
  64.            }
  65.         HL = HL->ACF_LIST.Next;
  66.      }
  67.    return (found);
  68. } /* IsLoopVar */
  69.  
  70. /* The following subroutine is used for chaining definitions and uses */
  71.  
  72. void DepChaining (R_In, Defs, Uses, Depth, R_Out)
  73. pDepNodeSet Uses, Defs, R_In, R_Out;
  74. int Depth;
  75.  
  76. /* means :  Bestimmung von OUT-Mengen fuer Basis-Knoten im ACF_Graphen
  77.    USE       : Benutzungen in elementaren Knoten
  78.    DEF       : Definitionen in elementaren Knoten
  79.    R_IN      : Menge der Defintionen/Benutzungen, die Knoten N erreichen
  80.    LOOPLIST  : <Lm,...,L1> Liste der Schleifen, die N umgeben; Lm ist
  81.                innerste, L1 ist aeusserste Schleife
  82.    DEPTH     : Anzahl umgebender Schleifen, die nicht konstant gehalten werden
  83.                d.h. L1, ..., Lk mit k = m - Depth werden konstant gehalten
  84.    R_OUT     : Mengen der Defintionen/Benutzungen, die Ausgang von N erreichen
  85.  
  86.    Bemerkung : Nur fuer DEPTH = 0 werden Defintionen und Benutzungen aus Knoten
  87.                N betrachtet, ob sie entsprechende Ausgaenge erreichen
  88.  
  89.   global used : LoopList */
  90.  
  91. {
  92.    printf ("*** Start : DepChaining\\n");
  93.    printf ("R_In : "); WriteSet (stdout, R_In); printf("\\n");
  94.    printf ("Defs : "); WriteSet (stdout, Defs); printf("\\n");
  95.    printf ("Uses : "); WriteSet (stdout, Uses); printf("\\n");
  96.    Assign (R_Out, R_In);
  97.    Union (R_Out, Uses);
  98.    Union (R_Out, Defs);
  99.    ReleaseSet (Uses);
  100.    ReleaseSet (Defs);
  101.    printf ("R_Out : "); WriteSet (stdout, R_Out); printf("\\n");
  102.    printf ("*** End : DepChaining\\n");
  103. } /* depchaining , means basic i-o */
  104.  
  105.  
  106.  
  107. static FILE * yyf = stdout;
  108.  
  109. static void yyAbort
  110. # ifdef __cplusplus
  111.  (char * yyFunction)
  112. # else
  113.  (yyFunction) char * yyFunction;
  114. # endif
  115. {
  116.  (void) fprintf (stderr, "Error: module DataFlow, routine %s failed\n", yyFunction);
  117.  exit (1);
  118. }
  119.  
  120. void DataFlow ARGS((tTree t));
  121. static void Building ARGS((tTree t));
  122. static void Reaching ARGS((tTree t, pDepNodeSet in, pDepNodeSet out, tExits eout, int depth, int new));
  123. void OutDependences ARGS((tTree t));
  124. static void OutDepNode ARGS((tDepGraph d));
  125. static void OutPosition ARGS((tTree t));
  126.  
  127. void DataFlow
  128. # if defined __STDC__ | defined __cplusplus
  129. (register tTree t)
  130. # else
  131. (t)
  132.  register tTree t;
  133. # endif
  134. {
  135. # line 96 "DataFlow.puma"
  136.  
  137. unsigned char string[256];
  138. DepNodeSet R_In, R_Out;
  139. tExits E_Out;
  140.  
  141.   if (t == NoTree) return;
  142.   if (t->Kind == kCOMP_UNIT) {
  143. # line 108 "DataFlow.puma"
  144.   {
  145. # line 109 "DataFlow.puma"
  146.    DataFlow (t->COMP_UNIT.COMP_ELEMENTS);
  147.   }
  148.    return;
  149.  
  150.   }
  151.   if (t->Kind == kDECL_LIST) {
  152. # line 114 "DataFlow.puma"
  153.   {
  154. # line 115 "DataFlow.puma"
  155.    DataFlow (t->DECL_LIST.Elem);
  156. # line 116 "DataFlow.puma"
  157.    DataFlow (t->DECL_LIST.Next);
  158.   }
  159.    return;
  160.  
  161.   }
  162.   if (t->Kind == kPROGRAM_DECL) {
  163. # line 119 "DataFlow.puma"
  164.   {
  165. # line 120 "DataFlow.puma"
  166.    DepCreateGraph (t);
  167. # line 121 "DataFlow.puma"
  168.    GetString (t->PROGRAM_DECL.Name, string);
  169. # line 122 "DataFlow.puma"
  170.    printf ("PROGRAM %s; \n", string);
  171. # line 123 "DataFlow.puma"
  172.    DataFlow (t->PROGRAM_DECL.PROGRAM_BODY);
  173. # line 124 "DataFlow.puma"
  174.    DepCloseGraph ();
  175.   }
  176.    return;
  177.  
  178.   }
  179.   if (t->Kind == kPROC_DECL) {
  180. # line 127 "DataFlow.puma"
  181.   {
  182. # line 128 "DataFlow.puma"
  183.    DepCreateGraph (t);
  184. # line 129 "DataFlow.puma"
  185.    GetString (t->PROC_DECL.Name, string);
  186. # line 130 "DataFlow.puma"
  187.    printf ("SUBROUTINE %s; \n", string);
  188. # line 131 "DataFlow.puma"
  189.    DataFlow (t->PROC_DECL.PROC_BODY);
  190. # line 132 "DataFlow.puma"
  191.    DepCloseGraph ();
  192.   }
  193.    return;
  194.  
  195.   }
  196.   if (t->Kind == kFUNC_DECL) {
  197. # line 135 "DataFlow.puma"
  198.   {
  199. # line 136 "DataFlow.puma"
  200.    DepCreateGraph (t);
  201. # line 137 "DataFlow.puma"
  202.    GetString (t->FUNC_DECL.Name, string);
  203. # line 138 "DataFlow.puma"
  204.    printf ("FUNCTION %s; \n", string);
  205. # line 139 "DataFlow.puma"
  206.    DataFlow (t->FUNC_DECL.FUNC_BODY);
  207. # line 140 "DataFlow.puma"
  208.    DepCloseGraph ();
  209.   }
  210.    return;
  211.  
  212.   }
  213.   if (t->Kind == kBODY_NODE) {
  214. # line 143 "DataFlow.puma"
  215.   {
  216. # line 144 "DataFlow.puma"
  217.    Building (t->BODY_NODE.STATS);
  218. # line 145 "DataFlow.puma"
  219.    MakeSet (& R_In, MaxDepNode);
  220. # line 146 "DataFlow.puma"
  221.    MakeSet (& R_Out, MaxDepNode);
  222. # line 147 "DataFlow.puma"
  223.    printf ("Calling of Reaching from Body\n");
  224. # line 148 "DataFlow.puma"
  225.    Reaching (t, & R_In, & R_Out, E_Out, 0, 1);
  226. # line 149 "DataFlow.puma"
  227.    ReleaseSet (& R_In);
  228. # line 150 "DataFlow.puma"
  229.    ReleaseSet (& R_Out);
  230.   }
  231.    return;
  232.  
  233.   }
  234. ;
  235. }
  236.  
  237. static void Building
  238. # if defined __STDC__ | defined __cplusplus
  239. (register tTree t)
  240. # else
  241. (t)
  242.  register tTree t;
  243. # endif
  244. {
  245. # line 161 "DataFlow.puma"
  246.  
  247. unsigned char string[256];
  248.  
  249.   if (t == NoTree) return;
  250.  
  251.   switch (t->Kind) {
  252.   case kVAR_DECL:
  253. # line 171 "DataFlow.puma"
  254.    return;
  255.  
  256.   case kPARAMETER_DECL:
  257. # line 174 "DataFlow.puma"
  258.    return;
  259.  
  260.   case kCOMMON_DECL:
  261. # line 177 "DataFlow.puma"
  262.   {
  263. # line 179 "DataFlow.puma"
  264.    Building (t->COMMON_DECL.IDS);
  265.   }
  266.    return;
  267.  
  268.   case kEQV_DECL:
  269. # line 182 "DataFlow.puma"
  270.   {
  271. # line 184 "DataFlow.puma"
  272.    Building (t->EQV_DECL.VARS);
  273.   }
  274.    return;
  275.  
  276.   case kDATA_DECL:
  277. # line 187 "DataFlow.puma"
  278.   {
  279. # line 188 "DataFlow.puma"
  280.    Building (t->DATA_DECL.VARS);
  281. # line 189 "DataFlow.puma"
  282.    Building (t->DATA_DECL.VALS);
  283.   }
  284.    return;
  285.  
  286.   case kTYPE_LIST:
  287. # line 207 "DataFlow.puma"
  288.   {
  289. # line 208 "DataFlow.puma"
  290.    Building (t->TYPE_LIST.Elem);
  291. # line 209 "DataFlow.puma"
  292.    Building (t->TYPE_LIST.Next);
  293.   }
  294.    return;
  295.  
  296.   case kINDEX_TYPE:
  297. # line 212 "DataFlow.puma"
  298.   {
  299. # line 213 "DataFlow.puma"
  300.    Building (t->INDEX_TYPE.LOWER);
  301. # line 214 "DataFlow.puma"
  302.    Building (t->INDEX_TYPE.UPPER);
  303.   }
  304.    return;
  305.  
  306.   case kACF_LIST:
  307. # line 223 "DataFlow.puma"
  308.   {
  309. # line 224 "DataFlow.puma"
  310.  Stat = t->ACF_LIST.Elem;
  311. # line 225 "DataFlow.puma"
  312.    Building (t->ACF_LIST.Elem);
  313. # line 226 "DataFlow.puma"
  314.    Building (t->ACF_LIST.Next);
  315.   }
  316.    return;
  317.  
  318.   case kACF_BASIC:
  319. # line 229 "DataFlow.puma"
  320.   {
  321. # line 230 "DataFlow.puma"
  322.    Building (t->ACF_BASIC.BASIC_STMT);
  323.   }
  324.    return;
  325.  
  326.   case kACF_IF:
  327. # line 233 "DataFlow.puma"
  328.   {
  329. # line 234 "DataFlow.puma"
  330.    Building (t->ACF_IF.IF_EXP);
  331. # line 235 "DataFlow.puma"
  332.    Building (t->ACF_IF.THEN_PART);
  333. # line 236 "DataFlow.puma"
  334.    Building (t->ACF_IF.ELSE_PART);
  335.   }
  336.    return;
  337.  
  338.   case kACF_WHERE:
  339. # line 239 "DataFlow.puma"
  340.   {
  341. # line 240 "DataFlow.puma"
  342.    Building (t->ACF_WHERE.WHERE_EXP);
  343. # line 241 "DataFlow.puma"
  344.    Building (t->ACF_WHERE.TRUE_PART);
  345. # line 242 "DataFlow.puma"
  346.    Building (t->ACF_WHERE.FALSE_PART);
  347.   }
  348.    return;
  349.  
  350.   case kACF_CASE:
  351. # line 245 "DataFlow.puma"
  352.   {
  353. # line 246 "DataFlow.puma"
  354.    Building (t->ACF_CASE.CASE_EXP);
  355. # line 247 "DataFlow.puma"
  356.    Building (t->ACF_CASE.CASE_ALTS);
  357. # line 248 "DataFlow.puma"
  358.    Building (t->ACF_CASE.CASE_OTHERWISE);
  359.   }
  360.    return;
  361.  
  362.   case kACF_WHILE:
  363. # line 251 "DataFlow.puma"
  364.   {
  365. # line 252 "DataFlow.puma"
  366.  LoopList = mACF_LIST (t, LoopList);
  367. # line 253 "DataFlow.puma"
  368.    Building (t->ACF_WHILE.WHILE_EXP);
  369. # line 254 "DataFlow.puma"
  370.    Building (t->ACF_WHILE.WHILE_BODY);
  371. # line 255 "DataFlow.puma"
  372.  LoopList = LoopList->ACF_LIST.Next;
  373.   }
  374.    return;
  375.  
  376.   case kACF_DO:
  377. # line 258 "DataFlow.puma"
  378.   {
  379. # line 259 "DataFlow.puma"
  380.  LoopList = mACF_LIST (t, LoopList);
  381. # line 260 "DataFlow.puma"
  382.    Building (t->ACF_DO.DO_RANGE);
  383. # line 261 "DataFlow.puma"
  384.    Building (t->ACF_DO.DO_BODY);
  385. # line 262 "DataFlow.puma"
  386.  LoopList = LoopList->ACF_LIST.Next;
  387.   }
  388.    return;
  389.  
  390.   case kASSIGN_STMT:
  391. # line 265 "DataFlow.puma"
  392.   {
  393. # line 266 "DataFlow.puma"
  394.    Building (t->ASSIGN_STMT.ASSIGN_VAR);
  395. # line 267 "DataFlow.puma"
  396.    Building (t->ASSIGN_STMT.ASSIGN_EXP);
  397.   }
  398.    return;
  399.  
  400.   case kCALL_STMT:
  401. # line 270 "DataFlow.puma"
  402.   {
  403. # line 271 "DataFlow.puma"
  404.    Building (t->CALL_STMT.CALL_PARAMS);
  405.   }
  406.    return;
  407.  
  408.   case kBTP_LIST:
  409. # line 280 "DataFlow.puma"
  410.   {
  411. # line 281 "DataFlow.puma"
  412.    Building (t->BTP_LIST.Elem);
  413. # line 282 "DataFlow.puma"
  414.    Building (t->BTP_LIST.Next);
  415.   }
  416.    return;
  417.  
  418.   case kVAR_PARAM:
  419. # line 285 "DataFlow.puma"
  420.   {
  421. # line 286 "DataFlow.puma"
  422.    Building (t->VAR_PARAM.V);
  423.   }
  424.    return;
  425.  
  426.   case kVALUE_PARAM:
  427. # line 289 "DataFlow.puma"
  428.   {
  429. # line 290 "DataFlow.puma"
  430.    printf ("There shouldn't be any value params in FORTRAN\n");
  431.   }
  432.    return;
  433.  
  434.   case kBTE_LIST:
  435. # line 293 "DataFlow.puma"
  436.   {
  437. # line 294 "DataFlow.puma"
  438.    Building (t->BTE_LIST.Elem);
  439. # line 295 "DataFlow.puma"
  440.    Building (t->BTE_LIST.Next);
  441.   }
  442.    return;
  443.  
  444.   case kVAR_EXP:
  445.   if (t->VAR_EXP.V->Kind == kUSED_VAR) {
  446. # line 304 "DataFlow.puma"
  447.   {
  448. # line 305 "DataFlow.puma"
  449.    GetString (t->VAR_EXP.V->USED_VAR.VARNAME->VAR_OBJ.Ident, string);
  450. # line 306 "DataFlow.puma"
  451.  if (IsLoopVar (t->VAR_EXP.V->USED_VAR.VARNAME->VAR_OBJ.Ident))
  452.             { printf ("%s is LoopVariable\n",string);
  453.               t->VAR_EXP.V->Kind = kLOOP_VAR;
  454.             }
  455.           else
  456.             {
  457.               printf ("%s will be a use-node\n", string);
  458.               DN = mDepNode (t->VAR_EXP.V->USED_VAR.VARNAME->VAR_OBJ.Ident, 0, t->VAR_EXP.V, Stat, LoopList);
  459.               DepGraphNodeInsert (DN);
  460.             }
  461.  
  462.   }
  463.    return;
  464.  
  465.   }
  466.   if (t->VAR_EXP.V->Kind == kINDEXED_VAR) {
  467.   if (t->VAR_EXP.V->INDEXED_VAR.IND_VAR->Kind == kUSED_VAR) {
  468. # line 337 "DataFlow.puma"
  469.   {
  470. # line 338 "DataFlow.puma"
  471.    GetString (t->VAR_EXP.V->INDEXED_VAR.IND_VAR->USED_VAR.VARNAME->VAR_OBJ.Ident, string);
  472. # line 339 "DataFlow.puma"
  473.  DN = mDepNode (t->VAR_EXP.V->INDEXED_VAR.IND_VAR->USED_VAR.VARNAME->VAR_OBJ.Ident, 0, t->VAR_EXP.V, Stat, LoopList);
  474. # line 340 "DataFlow.puma"
  475.    DepGraphNodeInsert (DN);
  476. # line 341 "DataFlow.puma"
  477.    printf ("%s will be a use-node\n", string);
  478.   }
  479.    return;
  480.  
  481.   }
  482.   }
  483. # line 392 "DataFlow.puma"
  484.   {
  485. # line 393 "DataFlow.puma"
  486.    printf ("Building for VarExp should not be called here\n");
  487.   }
  488.    return;
  489.  
  490.   case kUSED_VAR:
  491. # line 319 "DataFlow.puma"
  492.   {
  493. # line 320 "DataFlow.puma"
  494.    GetString (t->USED_VAR.VARNAME->VAR_OBJ.Ident, string);
  495. # line 321 "DataFlow.puma"
  496.  if (IsLoopVar (t->USED_VAR.VARNAME->VAR_OBJ.Ident))
  497.             { printf ("LoopVariable %s is set \n",string);
  498.             }
  499.           else
  500.             {
  501.               printf ("%s will be a def-node \n", string);
  502.               DN = mDepNode (t->USED_VAR.VARNAME->VAR_OBJ.Ident, 1, t, Stat, LoopList);
  503.               DepGraphNodeInsert (DN);
  504.             }
  505.  
  506.   }
  507.    return;
  508.  
  509.   case kLOOP_VAR:
  510. # line 333 "DataFlow.puma"
  511.    return;
  512.  
  513.   case kINDEXED_VAR:
  514.   if (t->INDEXED_VAR.IND_VAR->Kind == kUSED_VAR) {
  515. # line 344 "DataFlow.puma"
  516.   {
  517. # line 345 "DataFlow.puma"
  518.    Building (t->INDEXED_VAR.IND_EXPS);
  519. # line 346 "DataFlow.puma"
  520.  DN = mDepNode (t->INDEXED_VAR.IND_VAR->USED_VAR.VARNAME->VAR_OBJ.Ident, 1, t, Stat, LoopList);
  521. # line 347 "DataFlow.puma"
  522.    DepGraphNodeInsert (DN);
  523. # line 348 "DataFlow.puma"
  524.    GetString (t->INDEXED_VAR.IND_VAR->USED_VAR.VARNAME->VAR_OBJ.Ident, string);
  525. # line 349 "DataFlow.puma"
  526.    printf ("%s will be a def-node\n", string);
  527.   }
  528.    return;
  529.  
  530.   }
  531.   break;
  532.   case kVAR_OBJ:
  533. # line 358 "DataFlow.puma"
  534.    return;
  535.  
  536.   case kDUMMY_EXP:
  537. # line 367 "DataFlow.puma"
  538.    return;
  539.  
  540.   case kCONST_EXP:
  541. # line 370 "DataFlow.puma"
  542.    return;
  543.  
  544.   case kARRAY_EXP:
  545. # line 373 "DataFlow.puma"
  546.   {
  547. # line 374 "DataFlow.puma"
  548.    Building (t->ARRAY_EXP.ELEMENTS);
  549.   }
  550.    return;
  551.  
  552.   case kSLICE_EXP:
  553. # line 377 "DataFlow.puma"
  554.   {
  555. # line 378 "DataFlow.puma"
  556.    Building (t->SLICE_EXP.START);
  557. # line 379 "DataFlow.puma"
  558.    Building (t->SLICE_EXP.STOP);
  559. # line 380 "DataFlow.puma"
  560.    Building (t->SLICE_EXP.INC);
  561.   }
  562.    return;
  563.  
  564.   case kOP_EXP:
  565. # line 383 "DataFlow.puma"
  566.   {
  567. # line 384 "DataFlow.puma"
  568.    Building (t->OP_EXP.OPND1);
  569. # line 385 "DataFlow.puma"
  570.    Building (t->OP_EXP.OPND2);
  571.   }
  572.    return;
  573.  
  574.   case kOP1_EXP:
  575. # line 388 "DataFlow.puma"
  576.   {
  577. # line 389 "DataFlow.puma"
  578.    Building (t->OP1_EXP.OPND);
  579.   }
  580.    return;
  581.  
  582.   case kFUNC_CALL_EXP:
  583. # line 396 "DataFlow.puma"
  584.   {
  585. # line 397 "DataFlow.puma"
  586.    Building (t->FUNC_CALL_EXP.FUNC_PARAMS);
  587.   }
  588.    return;
  589.  
  590.   }
  591.  
  592. ;
  593. }
  594.  
  595. static void Reaching
  596. # if defined __STDC__ | defined __cplusplus
  597. (register tTree t, pDepNodeSet in, pDepNodeSet out, tExits eout, register int depth, register int new)
  598. # else
  599. (t, in, out, eout, depth, new)
  600.  register tTree t;
  601.  pDepNodeSet in;
  602.  pDepNodeSet out;
  603.  tExits eout;
  604.  register int depth;
  605.  register int new;
  606. # endif
  607. {
  608. # line 438 "DataFlow.puma"
  609.  
  610. DepNodeSet H, Defs, Uses;
  611.  
  612.   if (t == NoTree) return;
  613.  
  614.   switch (t->Kind) {
  615.   case kBODY_NODE:
  616. # line 442 "DataFlow.puma"
  617.   {
  618. # line 444 "DataFlow.puma"
  619.    printf ("R_IN : ");
  620. # line 444 "DataFlow.puma"
  621.    WriteSet (stdout, in);
  622. # line 444 "DataFlow.puma"
  623.    printf ("\n");
  624. # line 445 "DataFlow.puma"
  625.    printf ("R_OUT : ");
  626. # line 445 "DataFlow.puma"
  627.    WriteSet (stdout, out);
  628. # line 445 "DataFlow.puma"
  629.    printf ("\n");
  630. # line 446 "DataFlow.puma"
  631.    Reaching (t->BODY_NODE.STATS, in, out, eout, depth, new);
  632.   }
  633.    return;
  634.  
  635.   case kACF_EMPTY:
  636. # line 455 "DataFlow.puma"
  637.   {
  638. # line 456 "DataFlow.puma"
  639.    Assign (out, in);
  640.   }
  641.    return;
  642.  
  643.   case kACF_LIST:
  644. # line 459 "DataFlow.puma"
  645.   {
  646. # line 466 "DataFlow.puma"
  647.    printf ("ACF_LIST: R_IN = ");
  648. # line 466 "DataFlow.puma"
  649.    WriteSet (stdout, in);
  650. # line 466 "DataFlow.puma"
  651.    printf ("\n");
  652. # line 467 "DataFlow.puma"
  653.    MakeSet (& H, MaxDepNode);
  654. # line 468 "DataFlow.puma"
  655.    Reaching (t->ACF_LIST.Elem, in, & H, eout, depth, new);
  656. # line 469 "DataFlow.puma"
  657.    Reaching (t->ACF_LIST.Next, & H, out, eout, depth, new);
  658. # line 470 "DataFlow.puma"
  659.    printf ("ACF_LIST: R_OUT = ");
  660. # line 470 "DataFlow.puma"
  661.    WriteSet (stdout, out);
  662. # line 470 "DataFlow.puma"
  663.    printf ("\n");
  664. # line 471 "DataFlow.puma"
  665.    ReleaseSet (& H);
  666.   }
  667.    return;
  668.  
  669.   case kACF_IF:
  670. # line 474 "DataFlow.puma"
  671.   {
  672. # line 485 "DataFlow.puma"
  673.    MakeSet (& H, MaxDepNode);
  674. # line 486 "DataFlow.puma"
  675.    DepGraphGetForStmt (t, & Defs, & Uses);
  676. # line 487 "DataFlow.puma"
  677.    DepChaining (in, & Defs, & Uses, depth, & H);
  678. # line 490 "DataFlow.puma"
  679.    Reaching (t->ACF_IF.THEN_PART, & H, out, eout, depth, 0);
  680. # line 491 "DataFlow.puma"
  681.    Reaching (t->ACF_IF.ELSE_PART, & H, out, eout, depth, 0);
  682. # line 492 "DataFlow.puma"
  683.    ReleaseSet (& H);
  684.   }
  685.    return;
  686.  
  687.   case kACF_WHERE:
  688. # line 495 "DataFlow.puma"
  689.   {
  690. # line 496 "DataFlow.puma"
  691.    MakeSet (& H, MaxDepNode);
  692. # line 497 "DataFlow.puma"
  693.    DepGraphGetForStmt (t, & Defs, & Uses);
  694. # line 498 "DataFlow.puma"
  695.    DepChaining (in, & Defs, & Uses, depth, & H);
  696. # line 499 "DataFlow.puma"
  697.    Reaching (t->ACF_WHERE.TRUE_PART, & H, out, eout, depth, 0);
  698. # line 500 "DataFlow.puma"
  699.    Reaching (t->ACF_WHERE.FALSE_PART, & H, out, eout, depth, 0);
  700. # line 501 "DataFlow.puma"
  701.    ReleaseSet (& H);
  702.   }
  703.    return;
  704.  
  705.   case kACF_CASE:
  706. # line 504 "DataFlow.puma"
  707.   {
  708. # line 525 "DataFlow.puma"
  709.    printf ("CASE not implemented for Reaching\n");
  710.   }
  711.    return;
  712.  
  713.   case kACF_WHILE:
  714. # line 528 "DataFlow.puma"
  715.   {
  716. # line 538 "DataFlow.puma"
  717.  LoopList = mACF_LIST (t, LoopList);
  718. # line 539 "DataFlow.puma"
  719.    Reaching (t->ACF_WHILE.WHILE_BODY, in, out, eout, depth, new);
  720. # line 540 "DataFlow.puma"
  721.  LoopList = LoopList->ACF_LIST.Next;
  722.   }
  723.    return;
  724.  
  725.   case kACF_REPEAT:
  726. # line 543 "DataFlow.puma"
  727.   {
  728. # line 553 "DataFlow.puma"
  729.  LoopList = mACF_LIST (t, LoopList);
  730. # line 554 "DataFlow.puma"
  731.    Reaching (t->ACF_REPEAT.REPEAT_BODY, in, out, eout, depth, new);
  732. # line 555 "DataFlow.puma"
  733.  LoopList = LoopList->ACF_LIST.Next;
  734.   }
  735.    return;
  736.  
  737.   case kACF_DO:
  738. # line 558 "DataFlow.puma"
  739.   {
  740. # line 571 "DataFlow.puma"
  741.  LoopList = mACF_LIST (t, LoopList);
  742. # line 572 "DataFlow.puma"
  743.    printf ("ACF_DO: R_IN = ");
  744. # line 572 "DataFlow.puma"
  745.    WriteSet (stdout, in);
  746. # line 572 "DataFlow.puma"
  747.    printf ("\n");
  748. # line 573 "DataFlow.puma"
  749.    Reaching (t->ACF_DO.DO_BODY, in, out, eout, depth, new);
  750. # line 574 "DataFlow.puma"
  751.    printf ("ACF_DO: R_OUT = ");
  752. # line 574 "DataFlow.puma"
  753.    WriteSet (stdout, out);
  754. # line 574 "DataFlow.puma"
  755.    printf ("\n");
  756. # line 575 "DataFlow.puma"
  757.  LoopList = LoopList->ACF_LIST.Next;
  758.   }
  759.    return;
  760.  
  761.   case kACF_BASIC:
  762.   if (t->ACF_BASIC.BASIC_STMT->Kind == kASSIGN_STMT) {
  763. # line 578 "DataFlow.puma"
  764.   {
  765. # line 580 "DataFlow.puma"
  766.    printf ("Reaching an assignment\n");
  767. # line 581 "DataFlow.puma"
  768.    printf ("ASSIGN: R_IN = ");
  769. # line 581 "DataFlow.puma"
  770.    WriteSet (stdout, in);
  771. # line 581 "DataFlow.puma"
  772.    printf ("\n");
  773. # line 582 "DataFlow.puma"
  774.    DepGraphGetForStmt (t, & Defs, & Uses);
  775. # line 583 "DataFlow.puma"
  776.    DepChaining (in, & Defs, & Uses, depth, out);
  777. # line 584 "DataFlow.puma"
  778.    printf ("ASSIGN: R_OUT : ");
  779. # line 584 "DataFlow.puma"
  780.    WriteSet (stdout, out);
  781. # line 584 "DataFlow.puma"
  782.    printf ("\n");
  783.   }
  784.    return;
  785.  
  786.   }
  787.   if (t->ACF_BASIC.BASIC_STMT->Kind == kCALL_STMT) {
  788. # line 587 "DataFlow.puma"
  789.   {
  790. # line 589 "DataFlow.puma"
  791.    DepGraphGetForStmt (t, & Defs, & Uses);
  792. # line 590 "DataFlow.puma"
  793.    DepChaining (in, & Defs, & Uses, depth, out);
  794.   }
  795.    return;
  796.  
  797.   }
  798. # line 593 "DataFlow.puma"
  799.   {
  800. # line 594 "DataFlow.puma"
  801.    Assign (out, in);
  802. # line 595 "DataFlow.puma"
  803.    printf ("No Data Flow for this Statement\n");
  804.   }
  805.    return;
  806.  
  807.   }
  808.  
  809. # line 598 "DataFlow.puma"
  810.   {
  811. # line 599 "DataFlow.puma"
  812.    Assign (out, in);
  813. # line 600 "DataFlow.puma"
  814.    printf ("Error: Unknown Node for Reaching\n");
  815.   }
  816.    return;
  817.  
  818. ;
  819. }
  820.  
  821. void OutDependences
  822. # if defined __STDC__ | defined __cplusplus
  823. (register tTree t)
  824. # else
  825. (t)
  826.  register tTree t;
  827. # endif
  828. {
  829. # line 611 "DataFlow.puma"
  830.  
  831. unsigned char string[256];
  832. tDepNode DN;
  833. DepNodeSet Defs, Uses;
  834. int i, count;
  835.  
  836.   if (t == NoTree) return;
  837.   if (t->Kind == kCOMP_UNIT) {
  838. # line 618 "DataFlow.puma"
  839.   {
  840. # line 619 "DataFlow.puma"
  841.    OutDependences (t->COMP_UNIT.COMP_ELEMENTS);
  842.   }
  843.    return;
  844.  
  845.   }
  846.   if (t->Kind == kDECL_LIST) {
  847. # line 622 "DataFlow.puma"
  848.   {
  849. # line 623 "DataFlow.puma"
  850.    OutDependences (t->DECL_LIST.Elem);
  851. # line 624 "DataFlow.puma"
  852.    OutDependences (t->DECL_LIST.Next);
  853.   }
  854.    return;
  855.  
  856.   }
  857.   if (t->Kind == kPROGRAM_DECL) {
  858. # line 627 "DataFlow.puma"
  859.   {
  860. # line 628 "DataFlow.puma"
  861.    DepOpenGraph (t);
  862. # line 629 "DataFlow.puma"
  863.    GetString (t->PROGRAM_DECL.Name, string);
  864. # line 630 "DataFlow.puma"
  865.    fprintf (DepFile, "PROGRAM %s; \n", string);
  866. # line 631 "DataFlow.puma"
  867.  DepGraphAllNodes (&count, &Defs, &Uses);
  868.           fprintf (DepFile, "There are %d nodes\n", count);
  869.           fprintf (DepFile, "%d Definitions, %d Uses\n",
  870.                    Card(&Defs), Card(&Uses));
  871.           for (i=1; i<= count; i++)
  872.              { DN = DepGraphGetNode (i);
  873.                OutDepNode (DN);         }
  874. # line 638 "DataFlow.puma"
  875.    fprintf (DepFile, "\n");
  876. # line 639 "DataFlow.puma"
  877.    DepCloseGraph ();
  878.   }
  879.    return;
  880.  
  881.   }
  882.   if (t->Kind == kPROC_DECL) {
  883. # line 642 "DataFlow.puma"
  884.   {
  885. # line 643 "DataFlow.puma"
  886.    DepOpenGraph (t);
  887. # line 644 "DataFlow.puma"
  888.    GetString (t->PROC_DECL.Name, string);
  889. # line 645 "DataFlow.puma"
  890.    fprintf (DepFile, "SUBROUTINE %s \n", string);
  891. # line 646 "DataFlow.puma"
  892.  DepGraphAllNodes (&count, &Defs, &Uses);
  893.           fprintf (DepFile, "There are %d nodes\n", count);
  894.           fprintf (DepFile, "%d Definitions, %d Uses\n",
  895.                    Card(&Defs), Card(&Uses));
  896.           for (i=1; i<= count; i++)
  897.              { DN = DepGraphGetNode (i);
  898.                OutDepNode (DN);         }
  899. # line 653 "DataFlow.puma"
  900.    fprintf (DepFile, "\n");
  901. # line 654 "DataFlow.puma"
  902.    DepCloseGraph ();
  903.   }
  904.    return;
  905.  
  906.   }
  907.   if (t->Kind == kFUNC_DECL) {
  908. # line 657 "DataFlow.puma"
  909.   {
  910. # line 658 "DataFlow.puma"
  911.    DepOpenGraph (t);
  912. # line 659 "DataFlow.puma"
  913.    GetString (t->FUNC_DECL.Name, string);
  914. # line 660 "DataFlow.puma"
  915.    fprintf (DepFile, "FUNCTION %s; \n", string);
  916. # line 661 "DataFlow.puma"
  917.  DepGraphAllNodes (&count, &Defs, &Uses);
  918.           fprintf (DepFile, "There are %d nodes\n", count);
  919.           fprintf (DepFile, "%d Definitions, %d Uses\n",
  920.                    Card(&Defs), Card(&Uses));
  921.           for (i=1; i<= count; i++)
  922.              { DN = DepGraphGetNode (i);
  923.                OutDepNode (DN);         }
  924. # line 668 "DataFlow.puma"
  925.    fprintf (DepFile, "\n");
  926. # line 669 "DataFlow.puma"
  927.    DepCloseGraph ();
  928.   }
  929.    return;
  930.  
  931.   }
  932. ;
  933. }
  934.  
  935. static void OutDepNode
  936. # if defined __STDC__ | defined __cplusplus
  937. (register tDepGraph d)
  938. # else
  939. (d)
  940.  register tDepGraph d;
  941. # endif
  942. {
  943. # line 674 "DataFlow.puma"
  944.  
  945. unsigned char string[256];
  946.  
  947.   if (d == NoDepGraph) return;
  948.   if (d->Kind == kDepNode) {
  949. # line 678 "DataFlow.puma"
  950.   {
  951. # line 679 "DataFlow.puma"
  952.    GetString (d->DepNode.Name, string);
  953. # line 680 "DataFlow.puma"
  954.    fprintf (DepFile, "%s ", string);
  955. # line 681 "DataFlow.puma"
  956.    OutPosition (d->DepNode.Access);
  957. # line 682 "DataFlow.puma"
  958.    fprintf (DepFile, " : ");
  959. # line 683 "DataFlow.puma"
  960.    FileUnparse (DepFile, d->DepNode.Access);
  961. # line 684 "DataFlow.puma"
  962.    fprintf (DepFile, " kind = %d \n", d->DepNode.NodeKind);
  963.   }
  964.    return;
  965.  
  966.   }
  967. ;
  968. }
  969.  
  970. static void OutPosition
  971. # if defined __STDC__ | defined __cplusplus
  972. (register tTree t)
  973. # else
  974. (t)
  975.  register tTree t;
  976. # endif
  977. {
  978.   if (t == NoTree) return;
  979.   if (t->Kind == kUSED_VAR) {
  980. # line 689 "DataFlow.puma"
  981.   {
  982. # line 690 "DataFlow.puma"
  983.    fprintf (DepFile, "(P=%d)", t->USED_VAR.VARNAME->VAR_OBJ.Pos);
  984.   }
  985.    return;
  986.  
  987.   }
  988.   if (t->Kind == kINDEXED_VAR) {
  989. # line 693 "DataFlow.puma"
  990.   {
  991. # line 694 "DataFlow.puma"
  992.    OutPosition (t->INDEXED_VAR.IND_VAR);
  993.   }
  994.    return;
  995.  
  996.   }
  997. ;
  998. }
  999.  
  1000. void BeginDataFlow ()
  1001. {
  1002. # line 82 "DataFlow.puma"
  1003.  
  1004.   BeginDepGraph ();
  1005.   LoopList = mACF_EMPTY ();
  1006.   DepErrorCount = 0;
  1007.  
  1008. }
  1009.  
  1010. void CloseDataFlow ()
  1011. {
  1012. # line 89 "DataFlow.puma"
  1013.  
  1014.   if (DepErrorCount > 0)
  1015.      printf ("Fatal Errors for Data Flow Analysis ");
  1016.  
  1017. }
  1018.